package com.tuanbiao.presenter.setting;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.OnLifecycleEvent;

import com.hzjq.data.entity.SettingParams;
import com.hzjq.data.hzjq.entity.DeviceInfoEntity;
import com.tuanbiao.base.mvp.BasePresenter;
import com.tuanbiao.controllers.SettingController;
import com.tuanbiao.utils.SPHelper;

import timber.log.Timber;

/**
 * @author abiao
 * @since 2022/4/15 15:30
 */
public class SettingMorePresenter extends BasePresenter<SettingController.Model, SettingController.MoreView> implements SettingController.MorePresenter {
    private DeviceInfoEntity mDeviceInfoEntity;

    public SettingMorePresenter(SettingController.Model model, SettingController.MoreView rootView) {
        super(model, rootView);
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void onStarted() {
        SettingParams settingParams = mModel.getSettingParams();
        Timber.i(settingParams.toString());
        mRootView.showMaxDetonator(String.valueOf(settingParams.getMaxSupportPlanCapSize()));
        mRootView.showMaxDelay(String.valueOf(settingParams.getMaxSupportCapDelay()));
        mRootView.showModel(settingParams.isStandAloneModel());
        mRootView.showAllowPartNetted(mModel.isCapCountNotMatchAllowAdopt());
        mRootView.showSetting(SPHelper.showSettingControlPanel(),SPHelper.showSettingWorkModel()
                ,SPHelper.showSettingServerChange(),SPHelper.showDeviceNumChange(),SPHelper.showSettingLocalChange());
        mRootView.showForceBlastCheck(settingParams.isForceBlastCheck());
        mRootView.showForceAuthCheck(settingParams.isForceAuthCheck());
    }

    @Override
    public void setMaxDetonator(String content) {
        mModel.setMaxDetonator(Integer.parseInt(content));
        mRootView.showMaxDetonator(content);
        mRootView.showMessage("修改成功");
    }

    @Override
    public void setMaxDelay(String maxDelay) {
        mModel.setMaxDelay(Long.parseLong(maxDelay));
        mRootView.showMaxDelay(maxDelay);
        mRootView.showMessage("修改成功");
    }

    @Override
    public void setModel(boolean keep, boolean isStandAloneModel) {
        Timber.i("setModel:"+keep);
        mModel.setModel(keep, isStandAloneModel);
        mRootView.showModel(isStandAloneModel);
        mRootView.showMessage("修改成功");
        if (!isStandAloneModel) {
            mRootView.startLogin();
        }
    }

    @Override
    public void setShowControlPanel(boolean show) {
        SPHelper.setSettingControlPanel(show);
    }

    @Override
    public void setShowChangeModel(boolean show) {
        SPHelper.setSettingWorkModel(show);
    }

    @Override
    public void setShowChangeServer(boolean show) {
        SPHelper.setSettingServerVisibility(show);
    }

    @Override
    public void setShowChangeDeviceNum(boolean show) {
        SPHelper.setDeviceNumVisibility(show);
    }

    @Override
    public void setShowChangeLocal(boolean show) {
        SPHelper.setSettingLocalVisibility(show);
    }

    @Override
    public void changePartNetted(boolean allow) {
        mModel.setCapCountNotMatchAllowAdopt(allow);
        mRootView.showMessage("修改成功");
        mRootView.showAllowPartNetted(allow);
    }

    @Override
    public void changeForceBlast(boolean check) {
        mModel.changeForceBlast(check);
        mRootView.showMessage("修改成功");
        mRootView.showForceBlastCheck(check);
    }

    @Override
    public void changeForceAuth(boolean check) {
        mModel.changeForceAuth(check);
        mRootView.showMessage("修改成功");
        mRootView.showForceAuthCheck(check);
    }
}
